<template>
    <el-container class="container_wrap">
      <!-- 头部区域 -->
      <el-header class="header_wrap">
        
          <div class="systemInfo_wrap">
            <img src="../assets/heima.png" alt=""/>
            <span>电商后台管理系统</span>
          </div>
          <el-button type="info" @click="logout()" id="logout_btn">登出</el-button>
      </el-header>
      <!-- 页面主体区域 -->
      <el-container class="main_wrap">
        
        <!-- 侧边栏区域 -->
        <el-aside :width="isCollapse ? '64px' : '200px'" class="aside_area">
          <!-- 侧边栏收缩按钮 -->
          <div class="close_open_button" @click="changeCollapse()">{{this.isCollapse? '>>>':'<<<'}}</div>
          <!-- 侧边栏菜单区域 -->
          <el-menu
      background-color="#333744"
      text-color="#fff"
      active-text-color="#409eff" 
      :unique-opened="true" 
      class="el_menu" 
      :collapse="isCollapse"
      :collapse-transition="false"
      :router="true"
      :default-active="this.$router.history.current.path"
      >
      <!-- 一级菜单 -->
      <el-submenu :index="item.id.toString()" v-for="item in menuData" :key="item.id">
        <!-- 一级菜单模板 -->
        <template slot="title">
          <i :class="iconObjects[item.id]"></i>
          <span class="firstTitle">{{item.authName}}</span>
        </template>

        <!-- 二级菜单 -->
        <el-menu-item :index="'/' + item2.path" v-for="item2 in item.children" :key="item2.id">
                 <!-- 二级菜单模板 -->
        <template slot="title">
          <i class="iconfont icon-menu"></i>
          <span class="secondTitle">{{item2.authName}}</span>
        </template>
        </el-menu-item>
      </el-submenu>
    </el-menu>
        </el-aside>

        <el-container>
          <!-- 内容展示区域 -->
          <el-main>
            
            <router-view></router-view>

          </el-main>
          <!-- 底部区域 -->
          <el-footer class="foot_area">©2021 YeFang </el-footer>
        </el-container>

      </el-container>
    </el-container>
</template>

<script>
export default {

  created(){
    this.getMenuList();
  },
  data() {
    return {
      menuData:[],
      iconObjects:{
        '125':'iconfont icon-yonghuguanli',
        '103':'iconfont icon-quanxianguanli',
        '101':'iconfont icon-shangpinguanli',
        '102':'iconfont icon-ddguanli',
        '145':'iconfont icon-shujutongji'
      },
      isCollapse: false
    };
  },
  methods: {
    logout() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    async getMenuList(){
      const {data: res} = await this.$http.get('/menus');
      // console.log(res);
      if(res.meta.status !== 200){
        // 获取列表数据成功
        return this.$message.error(res.meta.msg)
      }
      // 获取成功，解构数据
      const {data : menuData} = res;
      this.menuData = menuData;
      // console.log(menuData);
    },
    changeCollapse(){
      this.isCollapse = !this.isCollapse;
    }
  },
};
</script>

<style lang="less" scoped>
.container_wrap {
  height: 100%;
}

.header_wrap {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  .systemInfo_wrap {
    display: flex;
    justify-content: center;
    align-items: center;
    color: #eaedf1;
    font-size: 25px;
    span {
      margin-left: 20px;
    }
  }
  #logout_btn {
    margin: 10px 0;
    text-align: center;
  }
}

.main_wrap {
  height: 100%;
}

.aside_area {
  background-color: #333744;
}

.main_wrap {
  background-color: #eaedf1;
}

.foot_area {
  background-color: #eaedf1;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 15px;
  color: #666;
  padding: 10px 0;
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}

.iconfont{
  margin-right: 15px;
}

.firstTitle{
  font-size: 15px;
}
.secondTitle{
  font-size: 13px;
}

.el_menu{
  border-right: 0;
}

.close_open_button{
  background-color: #4a5064;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #909399;
  letter-spacing: -0.1em;
  cursor: pointer;
}
</style>
